package utils;

import java.sql.*;

public class JdbcUtil {
    //(1)获取connection
    public static Connection getConnection() throws Exception {
        String url = "jdbc:mysql://localhost:3306/usermanager";
        String name = "root";
        String pwd = "root";
        String driver = "com.mysql.jdbc.Driver";
        Class.forName(driver);//连接驱动
        return DriverManager.getConnection(url, name, pwd);

    }

    //(2)释放资源
    public static void release(ResultSet resultSet, Statement statement, Connection connection) {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }

}